package cn.stylefeng.guns.modular.agv.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.agv.entity.AgvStorageTask;
import cn.stylefeng.guns.modular.agv.mapper.AgvStorageTaskMapper;
import cn.stylefeng.guns.modular.agv.model.params.AgvStorageTaskParam;
import cn.stylefeng.guns.modular.agv.model.result.AgvStorageTaskResult;
import  cn.stylefeng.guns.modular.agv.service.AgvStorageTaskService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * AGV拣货任务表 服务实现类
 * </p>
 *
 * @author zhangzh
 * @since 2024-08-06
 */
@Service
public class AgvStorageTaskServiceImpl extends ServiceImpl<AgvStorageTaskMapper, AgvStorageTask> implements AgvStorageTaskService {

    @Override
    public void add(AgvStorageTaskParam param){
        AgvStorageTask entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(AgvStorageTaskParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(AgvStorageTaskParam param){
        AgvStorageTask oldEntity = getOldEntity(param);
        AgvStorageTask newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public AgvStorageTaskResult findBySpec(AgvStorageTaskParam param){
        return null;
    }

    @Override
    public List<AgvStorageTaskResult> findListBySpec(AgvStorageTaskParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(AgvStorageTaskParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(AgvStorageTaskParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private AgvStorageTask getOldEntity(AgvStorageTaskParam param) {
        return this.getById(getKey(param));
    }

    private AgvStorageTask getEntity(AgvStorageTaskParam param) {
        AgvStorageTask entity = new AgvStorageTask();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
